package com.ikingtech.platform.service.system.dept.configuration;

import com.ikingtech.framework.sdk.component.api.CompDepartmentApi;
import com.ikingtech.framework.sdk.department.api.DeptOrgApi;
import com.ikingtech.framework.sdk.department.api.DeptUserApi;
import com.ikingtech.framework.sdk.organization.api.OrgDeptApi;
import com.ikingtech.framework.sdk.user.api.UserDeptApi;
import com.ikingtech.platform.service.system.dept.service.CompDepartmentService;
import com.ikingtech.platform.service.system.dept.service.OrgDeptService;
import com.ikingtech.platform.service.system.dept.service.UserDeptService;
import com.ikingtech.platform.service.system.dept.service.repository.DeptRepository;
import com.ikingtech.platform.service.system.dept.service.repository.ModelConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author tie yan
 */
@Configuration
public class DepartmentConfiguration {

    @Bean
    @ConditionalOnMissingBean({CompDepartmentApi.class})
    public CompDepartmentApi compDepartmentApi(DeptRepository repo, DeptOrgApi deptOrgApi, ModelConverter converter) {
        return new CompDepartmentService(repo, deptOrgApi, converter);
    }

    @Bean
    @ConditionalOnMissingBean({UserDeptApi.class})
    public UserDeptApi userDeptApi(DeptRepository repo, DeptOrgApi deptOrgApi, DeptUserApi deptUserApi) {
        return new UserDeptService(repo, deptOrgApi, deptUserApi);
    }

    @Bean
    @ConditionalOnMissingBean({OrgDeptApi.class})
    public OrgDeptApi orgDeptApi(DeptRepository repo) {
        return new OrgDeptService(repo);
    }
}
